Top 10k strings from Complete Machine Code Tutor, The (1984)(New Generation Software).tzx
in <root> / bin / z80 / software / Sinclair Spectrum Collection TOSEC.exe / Sinclair ZX Spectrum - Utilities & Educational / Sinclair ZX Spectrum - Utilities & Educational - [TZX] (TOSEC-v2007-01-01) /
Back to the directory listing
12 DEFM " ADD HL,HL 6 LD HL,STORE 5 ADD HL,DE 4 EX5B:DEFM " LD HL,(STORE) 4 DEFM "using addition to successively multiply by" 4 DEFM "number held in the HL register pair by 10" 4 DEFM " LD DE,(STORE) 4 DEFM " LD (STORE),HL 4 DEFM " ADD HL,DE 4 i.e. 7 6 5 4 3 2 1 0 C 4 LD HL,STORE 4 LD (HL),C 4 DJNZ LOOP 3 i.e. -2 is equivalent to 254 etc. 3 i.e. 01101100 3 ectively multiplies a" 3 When performing arithmetic operationswhich we wish to interpret within therange -128 to +127, the Carry flag nolonger signals an out of range result.However another flag, the overflow (P/V)flag does. It is a "1" whenever the answeris outside the range -128 to +127 and "0"within the range. It is effectively acarry into bit 7 which would make the signbit incorrect. 3 There is no reason for sticking to 8 bitsusing this method. So long as the numberof bits is sufficient and the mostsignificant bit is taken as the sign bitany size positive or negative number canbe represented. 3 The Z80 has two instructions that may beused for these operations 3 The Sign and overflow flags are alsooperative after ADC and SBC instruction onthe HL register. It reflects the 15th bit(or bit 7 of H register) . 3 Performing a similar calculation to theabove we can show that a register pair canrepresent a number in the range +32767 to-32768. 3 NEG negates, or makes negative, the contents of the Accumulator by complementing and adding 1 in one operation. 3 Load further lessons from tape 3 It is important to remember that the ZeroCarry, Sign, and overflow flags are alwaysoperative after an 8 bit arithmeticinstruction or a 16 bit addition involvingthe Carry. Your interpretation of theresult determines which flag(s) you shouldbe interested in. 3 CPL complements or inverts the contents of the Accumulator. 3 Although these examples appear to be allpositive, they can be viewed equally asnegative where appropriate and the Signand overflow flags observed operating.Remember a number above 128 is a negativenumber. Since all the negative numbers inthe examples are small, they can be seenquickly and simply be converted bysubtracting the number from 256. 3 A Sign flag (S) is provided on the Z80.It duplicates the sign ( bit 7 ) of theanswer after any arithmetic operation onthe Accumulator. The sign flag is "0" fora positive result and "1" for a negativeresult. 3 LD DE,FFFEH 3 LD A,(ST1) 3 LD (ST3),A 3 LD (HL),L 3 LD (DE),A 3 DJNZ LOOP2 3 ADD HL,HL 3 EXAMPLES OF +VE AND -VE NOTATION 2 ve number we can holdin a single register, using this notationis 01111111 or 127 and the largestnegative number 10000000 or -128. 2 the number 2 Three types, or modes, of maskableinterrupts are available. 2 The programmer can arrange that maskableinterrupts (MI) are ignored. Within theZ80 there is a flag, the interrupt enableflag, that can be set and cleared.Depending upon the state of this flag MIwill be accepted or ignored. 2 DEFM " RET 2 (viii)Return from interrupt (RETI). 2 (vii) Enables interrupts 2 (vi) POP or EXchange registers. 2 (v) Disable interrupt if required. 2 (iv) Do interrupt routine. 2 (ii ) PUSH or EXchange required registered(iii) Enables interrupt if required. 2 (i) Enter maskable interrupt, interrupts are disabled at this time. 2 i.e. C 7 6 5 4 3 2 1 0 2 You should now be able to use otherassemblers to write your own programs.You will find that most are not souser friendly, and that you will notbe able to one step easily throughinstructions. Don't despair. You canalways return to this Tutor to simulateyour problem. 2 We must return from an interrupt routinewith the instruction RETI ( RETurn from Interrupt ) and not RET. 2 To ensure that no other interrupt occursduring this period and therefore corruptsthe register contents before they aresafe, the interrupts are disabled duringthese operations. 2 This completes a study of all theinstructions available on the Z80 chip. 2 The two instructions that manipulate thisflag are 2 The last lessons deal with instructionsthat allow the outside world to interruptthe processor. 2 The final set of lessons introduces morespecialised registers and instructions,and looks at the way the Z80 can talk withthe outside world. 2 The example shows the use of the Refreshregister as a source of random numbers. 2 STORE DEFB 6 2 STORE BIN 69H 2 One Non-Maskable Interrupt is availableon the Z80 chip. The interruptautomatically performs an RST or CALL toaddress 0066H on completion of the currentinstructions. The routine at 0066H isperformed. The instruction RETN or RETurnfrom Non-maskable interrupt returnscontrol back to the interrupted routine atits next instruction . 2 MODE 2 is the most flexible, the addressto which the processor is forced is theindirect address held in a memorylocation. The address of this memorylocation is computed from the contentof the I register, which provides thehigh byte and the interrupting devicewhich provides the low byte. Sincethe interrupt routine is addressedindirectly the interrupts are termedvectored interrupts. 2 MODE 1 is the one used by the Sinclairsystem ROM. It is set by the instructionIM 1. This mode is similar in operation tothe Non Maskable Interrupt except thatprocessor is restarted at 0038H insteadof 0066H as in the NMI. 2 MODE 0 is set by the instruction IM 0.This mode is the one described previously,where the RST n instruction is forced ontothe data highway to fool the processorinto performing the restart. 2 LOOP LD A,R 2 LD HL,22528 2 Interrupts fall into two types, Non-Maskable Interrupts (NMI) and MaskableInterrupts (MI). Maskable interrupt can beignored by the software, but NMIs cannot. 2 Hence interrupt routine take the form:- 2 Entry into a maskable interruptautomatically disables interrupt. 2 EI Enable Interrupts. After one more single byte instruction, further interrupts are accepted. 2 DI Disable Interrupts immediately. 2 An interrupt originates from outside theprocessor, requesting it to break off itscurrent sequence of operations and dealwith some other function. 2 An interrupt can occur at any time.It follows therefore that if theinterrupted program is to be continued(i.e. be re entered), the contents of anyregister that the interrupt routine uses,must be stored or pushed onto the stack,and reloaded or POPped from the stackbefore returning 2 35. Finale 2 34. Interrupts 2 33. Processor control instructions 2 32. Block I/O instructions 2 31. Block search instructions 2 30. Block tranfer instructions 2 29. Block instructions - introduction 2 28. Input/Output instructions 2 27. The alternative set of registers 2 26. The index registers 2 SBC HL,DE 2 SBC HL,BC 2 LD B,(HL) 2 LD A,(NUM1) 2 LD A,(DE) 2 LD (LREG),HL 2 LD (HL),A 2 LD (HL),0 2 LD (22529),A 2 LD (22528),A 2 JR NZ,LOOP 2 JR LOOP1 2 EX AF,AF' 2 DJNZ LOOP3 2 DJNZ LOOP1 2 ADD A,(HL) 2 GOOD LUCK and HAPPY PROGRAMMING 2 Load earlier lessons for revision 2 EXAMPLE OF RELATIVE JUMPS 2 LESSONS 26 - 35 2 Ex - using alternative set 2 Ex - use of index registers 2 Ex - control instructions 2 Ex - block transfer 2 Ex - block search 2 Ex - block I/O 2 Ex - I/O instructions 2 INTRODUCTION 2 A after (HL) A before 2 INTRODUCTION 2 INTERRUPTS 1 yek yna sserp neht ,epat tratS 1 where x is any number and is unaffected bytne instruction. 1 uoloc dilavnI 1 transfer (HL) to (DE), increment HL and DE, decrement BC, set PV flag if BC=0 1 transfer (HL) to (DE), decrement HL, DE, and BC, set PV flag if BC=0 1 the port whose number is in C 1 the memory location (IY) 1 the memory location (IX) 1 the memory location (DE) 1 the memory location (BC) 1 the location (HL) 1 the contents of the Accumulator is eXclusively ORed with 1 the contents of 1 the computer is HALTed until an interrupt comes to awake it again 1 the carry flag is set, ie Set Carry Flag 1 the carry flag is inverted, ie Compliment Carry Flag 1 the alternative AF registers 1 the accumulator is ComPared with 1 the Stack Pointer 1 the Refresh register 1 the RETurn address is POPped from the stack 1 the L register 1 the Interrupt vector register 1 the IY register 1 the IX register 1 the HL register 1 the H register 1 the Flag register 1 the E register 1 the DE register 1 the D register 1 the C register 1 the BC, DE, HL registers are all EXchanged with the alternative set 1 the BC register 1 the B register 1 the Accumulator is logically ORed with 1 the Accumulator is logically ANDed with 1 the Accumulator is NEGated, ie made negative 1 the Accumulator 1 the AF registers 1 search from (HL) Incrementing BC bytes for data in Accumulator 1 search from (HL) Decrementing BC bytes for data in Accumulator 1 rotate the accumulator and carry Right 1 rotate the Accumulator and carry Left 1 rotate the Accumulator Right, shifting bit 0 into Carry 1 rotate the Accumulator Left shifting bit 7 into Carry 1 rotate Right Decimal contents of (HL) with least significant end of Accumulator 1 rotate Left Decimal contents of (HL) with least significant end of Accumulator 1 reSTart at address 1 r single register dd double register* flag affected . flag not affected n/v instruction not valid 1 push the return address to stack and CALL 1 port with the above number 1 perform relative jump to 1 perform jump to 1 output from (HL) to port (C) increment HL, decrement B 1 ouTput to port (C), from block from (HL) Decrementing HL for B bytes 1 ouTput from (HL) to port (C) block from (HL) Incrementing for B bytes 1 orre retemaraP 1 oog on POTMAR 1 of moor oN 1 oUTput from (HL) to port (C) Decrement HL, decrement B 1 norw tpircs+ 1 nemugra dilavnI 1 memory location 1 location (IY+offset) 1 location (IX+offset) 1 lif fo dnE 1 lcniS 2891 1 is loaded with 1 is Shifted Right Logically, 0 is shifted into bit 7 1 is Shifted Right Arithmetically, sign bit unchanged 1 is Shifted Left Arithmetically, 0 is shifted into bit 0 1 is Rotated Right, shifting bit 0 into Carry 1 is Rotated Left shifting bit 7 into Carry 1 is PUSHed onto the stack and the SP decremented by 2 1 is POPped from the stack and the SP incremented by 2 1 is INCremented by 1 1 is EXchanged with 1 is DECremented by 1 1 invert all bits in A register, ie ComPLiment 1 instruction Carry Zero 1 input data from 1 if the Zero flag is set, 1 if the Zero flag is not set, 1 if the Sign flag is set, ie Minus, 1 if the Sign flag is not set, ie Positive, 1 if the Parity flag is sEt, ie Parity is Even, 1 if the Parity flag is nOt set, ie Parity is Odd, 1 if the Carry flag is set, 1 if the Carry flag is not set, 1 ib oot rebmuN 1 iNput into (HL) from port (C) increment HL, decrement B 1 iNput into (HL) from port (C) Decrement HL, decrement B 1 iNput from port (C), into block from (HL) Incrementing HL for B bytes 1 iNput from port (C), into block from (HL) Decrementing HL for B bytes 1 i.e. carry ' ' ' ' 1 i.e. borrow 0 1 1 2 0 2 1 i.e. B8 hex = (B hex)* 16+ (8)* 1 1 i.e. 0 0 0 0 0 1 0 1 +5 1 has taken from it the carry and 1 has added to it the carry and 1 has added to it 1 enable Interrupts. NOT PERFORMED BY SIMULATOR. 1 eercs fo tXu 1 disable Interrupts. NOT PERFORMED BY SIMULATOR. 1 decrement B, if zero continue, if Not Zero perform relative jump to 1 decimal Adjust Accumulator 1 compare (HL) with A, increment HL, decrement BC 1 compare (HL) with A, decrement HL, and BC 1 change Interrupt Mode to 1 block transfer (BC) bytes starting at (HL) to (DE) incrementing 1 block transfer (BC) bytes starting at (HL) to (DE) decrementing 1 becomes c 1 0 1 1 0 0 0 1 c= old Carry 1 becomes 1 1 1 1 0 0 0 1 0 (-15 dec.) 1 becomes 1 1 0 1 1 0 0 0 1 old bit 0=1 RR r, and RR (HL) instructions ( RotateRight ) is similar to RL except that theshift around the 9 bits is to the right. 1 becomes 1 0 1 1 0 0 0 1 c c= old Carry 1 becomes 1 0 1 1 0 0 0 1 1 old bit 7=1 1 becomes 0 1 0 1 1 0 1 1 1 (91 dec.) 1 becomes 0 0 1 1 0 0 0 1 0 (49 dec.) 1 becomes 0 1 1 0 0 0 1 0 0 (196 dec.) 1 argorp otDz@ 1 and Carry are rotated Left 1 and Carry are Rotated Right 1 aerts dilavnI 1 \e"\c*\c"\a*\a"# 1 \["####\Y* 1 \G:\B"\E*8F 1 With an identical set for IY 1 USOG tuohtiw? 1 Tutor [ 1 This is the number we originally assumedat the beginning of our discussion. 1 There are no double register SUBinstructions. 1 The Accumulator has subtracted from it 1 The instruction should transfer thecontents of the block of memory 1000-2000 to memory locations 1500-2500.Unfortunately the first step transfersthe contents of 1000 to 1500. By the timeit is the turn of location 1500 to betransferred it has already beenoverwritten in the first step. 1 Space missing 1 Since the contents of the HL registerpair can be the result of some calculationthe jump can be conditional. 1 SUB r ) SUBtract from A, n, r, or 1 SUB n ) 1 SUB (IX+d) XOR (IX+d) 1 SUB (HL) ) (HL) 1 STZ[\]^_OP7RST) 1 SLA (IX+d) SRA (IX+d) SRL (IX+d) 1 SET N,r where N is the bit number 0-7SET N,(HL) 1 SET N (IX+d) RES N,(IX+d) BIT N,(IX+d) 1 SCF Set Carry Flag 1 SBC HL,BC ) SuBtract from HL with carrySBC HL,DE ) 1 SBC A,r ) SuBtract from A with carrySBC A,(HL)) 1 SBC A,n ) 1 SBC A,(IX+d) CP (IX+d) 1 S7:DEFM " EXAMPLE OF REGISTER PAIR ADDITION 1 S6:DEFM " EXAMPLES OF SINGLE REGISTER ADDITION 1 RST n where n = 00H, 08H, 10H, 18H, 20H, 28H, 30H, or 38H. 1 RRD Rotate Right Decimal (/10) 1 RR (IX+d) 1 RLD Rotate Left Decimal (*10) 1 RLC (IX+d) RL (IX+d) RRC (IX+d) 1 RETurn from Non-maskable interrupt: NOT PERFORMED BY SIMULATOR 1 RETurn from Interrupt: NOT PERFORMED BY SIMULATOR 1 RES N,(HL) 1 P8:DEFM " We can therefore load a register pair" 1 One difficulty with the above types ofjump is that, if the start address of theprogram were changed, all the jumpaddresses would require modification.Relative jumps do not have thisdifficulty. The absolute address is notstored with the instruction. It is thedifference between the current contents ofthe program counter and the address towhich we wish to jump that is storedwithin the instruction. Relative jumps arelimited to jumping backwards 128 locationsand forwards 127 locations. 1 Offset too big 1 Offset missing 1 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOk 1 OF tuohtiw 1 Number too large 1 Number missing 1 No OPeration is performed, inspite of this it takes .000001 seconds to do it 1 No DEFB, or DEFW 1 NOT DEFINED 1 N tuohtiw ROF 1 Missing space or , 1 Label too long 1 Label not found 1 LDIR pointer incremented and repeated until number found or BC=0 1 LDI pointer incremented 1 LDDR pointer decremented and repeated until number found or BC=0 1 LDD pointer decremented 1 LD r,r' where r and r' are any of the following: A,B,C,D,E,H and L. 1 LD r,n where n is a number 0 - 255 1 LD r,(IX+d) LD IX,nn LD SP,IX 1 LD r,(HL) where r is any single register A,B,C,D,E,H, or L. 1 LD dd,nn where dd is any register pair 1 LD dd,(nn) 1 LD A,(nn) where nn is a number 0 - 65535 1 LD (nn),dd 1 LD (IX+d),r LD IX,(nn) 1 LD (IX+d),n LD (nn),IX EX (SP),IX 1 JR e where e is the displacement inJR NC,e the range 127 to -128 1 JP Z,nn jump on zero 1 JP Z,nn jump if zero flag set 1 JP NZ,nn jump on not zero 1 JP NZ,nn jump if zero flag not set 1 JP NC,nn jump on no carry 1 JP NC,nn jump if carry flag not set 1 JP C,nn jump on carry 1 JP C,nn jump if carry flag set 1 Instruction unknown 1 IN A,(n) where n is the number of the input port (0-255) 1 Hence to make a positive number negativewe invert all its binary bits, known asComplimenting, and add 1. The notation isgenerally termed 2s complement 1 HL =1999 DE = 2499 and BC = 1000 andusing the LDDR instruction, the same blockwill be transferred to the same memorylocations without this problem. 1 HL = 1000 DE = 1500 and BC = 1000. 1 FLAGS$ Registers and Contents % STAC 1 Error after inst. 1 EXAMPLES OF BINARY CODED DECIMAL NOTATION 1 EX5A:DEFM " LD DE,8740 1 EX DE,HL exchanges register contents 1 EFM " INC DE 1 DJNZ e decrement and jump on non zero 1 DEFM "with the contents of a pair of memory" 1 DEFM "using this instruction. 1 DEFM "together numbers of any length. 1 DEFM "to the non-valid instructions LD E,(nn)" 1 DEFM "the only instruction that deals with the" 1 DEFM "the Lower address. 1 DEFM "the form LD r,r' are usually used to" 1 DEFM "the Spectrum keyboard is interrogated" 1 DEFM "the Low byte is held in the location with" 1 DEFM "results can be displayed easily. This" 1 DEFM "register addition only. The double length" 1 DEFM "register pairs with the contents of" 1 DEFM "register pair into a pair of memory" 1 DEFM "register pair addition, as well, to add" 1 DEFM "port is loaded into register r. Reading" 1 DEFM "numbers are held in BC and DE so that the" 1 DEFM "numbers 8740 and 1260 using single" 1 DEFM "method of addition can be performed using" 1 DEFM "locations, i.e. LD (nn),BC which is" 1 DEFM "locations, with instructions like" 1 DEFM "instructions LD (nn),C and LD (nn+1),B." 1 DEFM "instruction therefore divide 1 DEFM "equivalent to the two non-valid" 1 DEFM "displayed to the left of the registers. 1 DEFM "data is transferred into the processor. 1 DEFM "becomes 0 1 0 1 1 0 1 1 1 (91 dec.) 1 DEFM "are affected by this instruction and no" 1 DEFM "another register pair. Two instructions in" 1 DEFM "and LD D,(nn+1). 1 DEFM "Parity flags. The instruction IN F, (C) is" 1 DEFM "LD DE,(nn). This instruction is equivalent" 1 DEFM "IN r,(C), but the contents of the register" 1 DEFM "Flag register separately. Only the flags" 1 DEFM " into bit 7. 1 DEFM " i.e. 7 6 5 4 3 2 1 0 C 1 DEFM " This example effectively multiplies a" 1 DEFM " There are no instructions to load" 1 DEFM " The state of the individual flags are" 1 DEFM " The example adds together the two" 1 DEFM " The SRL or Shift Right Logically" 1 DEFM " Similarly, we can load the contents of a" 1 DEFM " STORE DEFB 25 1 DEFM " OUT (C), r is a similar instruction to" 1 DEFM " LOW DEFB 20 1 DEFM " IN r, (C) affect the Zero, Sign, and" 1 DEFM " HIGH DEFB 125 1 DEFM " LD HL,STORE 1 DEFM " LD HL,(STORE) 1 DEFM " LD C,A 1 DEFM " LD BC,32021 1 DEFM " LD BC,1260 1 DEFM " LD B,A 1 DEFM " LD A,E 1 DEFM " LD A,D 1 DEFM " LD A,15 1 DEFM " LD (HL),0 1 DEFM " LD (DE),A 1 DEFM " LD (BC),A 1 DEFM " JR LOOP1 1 DEFM " INC HL 1 DEFM " INC H 1 DEFM " DJNZ LOOP2 1 DEFM " ADD A,C 1 DEFM " ADD A,(HL) 1 DEFM " ADC A,B 1 DEFM " 1 0 1 1 0 1 1 1 x (183 dec.) 1 DEFM " and Carry 1 Cursor keys, delete, and auto-repeat are as standard. BREAK returns you to menu. 1 Can only ADD IX/IY 1 CPIR pointer incremented and repeated until number found or BC=0 1 CPI pointer incremented 1 CPDR pointer decremented and repeated until number found or BC=0 1 CPD pointer decremented 1 CP r Compares A with register r 1 CP n Compares A with n ( 0 - 255) 1 CP (HL) Compares A with memory location 1 CCF Compliment Carry Flag 1 Bracket missing 1 BIT N,(HL) 1 All these instructions affect not onlythe Carry flag, but the Zero, Sign, andParity flags. 1 All configurations of ADC instructionscan be used with SBC or SuBtract withCarry instructions. The operation issimilar to SUB, except that the result isdecremented by one if the carry flag isset. 1 ADDRESS MACHINE CODE SOURCE CODE 1 ADD IX,dd INC IX DEC IX 1 ADD A,r where r is any single 1 ADD A,n where n is a number 0 - 255 1 ADD A,(IX+d) INC (IX+d) AND (IX+d) 1 ADD A,(HL) 1 ADC A,(IX+d) DEC (IX+d) OR (IX+d) 1 ADC A,(HL) 1 ADC HL,dd SBC HL,dd and EX DE,HL arethe only exceptions. 1 :yarra retcarahC 1 :yarra rebmuN 1 /^3^7^D^Q^^^e^o^v^ 1 . Conventionally" 1 -^1^>^E^V^O^]^j^q^{^ 1 *^.^;^B^F^M^W^^^e^u^|^ 1 '^+^2^9^=^D^K^R^b^i^y^ 1 to thisfield. 1 since each digit can have one of tenstates, designated 0 - 9. 1 i.e. INI incrementing 1 i.e. C 7 6 5 4 3 2 1 0 1 gives 01000100 1 give 01111110 1 give 00111010 1 bit 7 6 5 4 3 2 1 0 1 after RRD 5 4 x 3 1 after RLD x 5 4 3 1 You are trying to run code in allocated storage area. RET missing? Please EDIT 1 You are about to write to memory which will affect your program. Please edit it. 1 You are about to affect memory area not allocated to you. Please edit program. 1 You may go through the example as manytimes as you like, until you understandit. If you still find difficulty, pressBREAK, skip over the lessons and re-ENTERthe lesson with which you are havingdifficulty. The manual however gives anoutline of each lesson. 1 X Press SPACE to continue. 1 While running this example try to predictthe state of the Zero flag after theinstruction has been performed. 1 When you do understand the examples giventry modifying them using the editor.Then try entering your own programs. Allprograms should end with RET ( or return).Don't worry if you forget, the simulatorwill tell you. 1 When data is transmitted from one placeto another, it is possible for errors toappear in the received data. Parity is asimple way of detecting single errors indata. An additional bit is added to thedata that makes the total number of "1"sin the word an even number. If thereceived word does not have an even numberof "1"s in it, then an error has occurred. In addition to this even parity we coulduse odd parity, where the word is made tohave an odd number of "1"s in it. 1 We would still like to be able to performcalculations on decimal numbers withouthaving to convert to binary or hexadecimalform. Hexidecimal form holds a key to amethod of achieving this. 1 We have so far treated information in theform of bytes or words. The Z80 does allowa number of operations on separate orgroups of bits within one byte 1 We shall then look at numbers held inregisters in more detail. 1 We require 16 different symbols torepresent a digit. 0-9 gives us thefirst 10 and A-F the final 6. A listof decimal, binary, and hexadecimalequivalents are given on the next screen. 1 We now introduce two new registers, theindex registers IX and IY. These tworegisters are identical in every way. Whatapplies to one applies to the other. 1 We have discussed flags as individualbits. This is the way they are normallyused. They are however actually stored inthe Z80 in a register, designated as F orflag register. The flags are arranged asfollows :- 1 We can also load a memory location withthe contents of the Accumulator withLD (nn),A where nn is the number oraddress of the memory location. 1 We can therefore load a register pairwith the contents of a pair of memorylocations, with instructions likeLD DE,(nn). This instruction is equivalentto the non-valid instructions LD E,(nn)and LD D,(nn+1). 1 We can load any of the register pairswith a number between 0 - 65535 directlyusing instructions like LD HL,nn. 1 We can input data directly into theaccumulator with IN A,(n) where n is thenumber of the input port between O and255. Similarly we can output data from theAccumulator to port n using theinstruction OUT (n),A. No flags areaffected by these instructions 1 We can also load any of the registerswith a number, n, between 0 and 255directly, with instructions like LD C,123.We shall discuss later from where thenumber is copied. Suffice to say, at thisstage, that instructions are stored asnumbers. For example LD A,B is stored as78. Look up in Appendix A of your SpectrumManual LD A,B and the number 78. Someinstructions like LD A,B are stored as onenumber, others take up to four. 1 We can also input data to any 8 bitregister using the B and C registers. Theinstruction IN r,(C), transmits thecontents of the B register to the portwhose number is in the C register. Theport may or may not act upon thisinformation. The returned data from theport is loaded into register r. Readingthe Spectrum keyboard is interrogatedusing this instruction. 1 Use of the BC and DE registers forindirect addressing is limited to the Aregister. i.e. LD (DE),A ; LD A,(BC) etc. 1 Up to now we have only used instructionsin which memory locations have beenspecified directly in the instruction.Another useful method of specifying amemory location is to use a number held ina register pair, known as indirectaddressing. The instruction LD B,(HL) forexample allows us to load or copy to the Bregister the contents of the memorylocation whose address is in the HLregister pair. 1 Try to predict the state of the Zero andCarry flags before performing thecomparison. In the next lessons we will beusing these flags extensively, to producemore interesting examples. 1 Transfers LD .....LDI,LDIR,LDD,LDDR 1 To perform this operation the Z80 usestwo further flags, the H flag ( a Halfcarry between nibbles ), and N flag( subtract instruction performed last ).Since these flags cannot be tested as partof a conditional jump etc. they are oflittle use. 1 To get round this problem use a label,declaring it in the label column in frontof the instruction to which you wish tojump. 1 This simple example counts up the numberof memory locations holding a number above192 and below 64 in the first 32 memorylocations. 1 This presentation is termed Binary CodedDecimal or BCD. 1 This group of lessons will introduce thethe idea of bit manipulation and its usein flag operations and in producing fastermethods of multiplication. 1 This group of instructions, together withthe interrupt instructions, control theaction of the processor. 1 This example uses shifts and rotateinstructions to multiply two 8 bitnumbers together. One number is rotatedto examine each bit in turn. The othernumber is also shifted and added to thetotal if the bit is set. This method isfar quicker than the method of repeatedaddition. 1 This example subtracts 1260 from 8740using only single register subtraction.The two numbers are held in allocatedmemory locations this time. 1 This example is a simple program toillustrate JP P,nn , and JP M,nn; jumpif positive and jump if minus. Note thatthe carry is still operative, andtherefore, if you do not clear it beforeADC and SBC the later jump could beunexpected. In this example the carry isnot cleared, so "look before you leap". 1 This example illustrates a method ofmultiplication. There are other fastermethods that will be shown later. 1 This example effectively multiplies anumber held in the HL register pair by 10using addition to successively multiply by2. 1 This method of subtraction can beextended to any length number and registerpair subtraction. 1 They cannot be exchanged for HL if thatregister pair is only implied in theinstruction, i.e. RRD. 1 They are simply those in which DE, or BCcan take part. The instruction equivalentto EX DE,HL is however EX (SP),HL, thatEXchanges the contents of the bottom ofthe Stack with the HL register. 1 They can take the place of the HLregister in most instructions. It issimpler to list the instructions that canbe performed by the HL register but notindex registers:- 1 These instructions are shift instructionsin which the bit that falls out one end ofthe register or memory location is pushedback into the other end. The Carry flageither forms part of the number shiftedthereby making it 9 bits long orduplicates the state of the bit that fellout of the register. There are thereforefour different types of rotate. 1 These examples illustrate the operationof rotate instructions. Modify the initialcondition of the location STORE toinvestigate their operation further. 1 These instructions can be used also tofill a block of memory with a singlenumber. 1 These instructions are primarily usedwhere counters are required. The operationon register pairs is also useful insequential operations on memory locationsutilising indirect addressing. 1 These examples show simple addition andsubtraction in BCD format. Remember tokeep in Hex display mode or theillustrations will not appear in BCD. 1 These examples illustrate indirectaddressing. At this stage it is impossibleto demonstrate its usefulness. It isemployed extensive in later examples 1 These examples illustrate themultiplication and division of BCD numbersby ten. 1 There are too many registers called up, to display. Program will RUN as normal. 1 There are only two more registers in theZ80 to discuss, the I or Interruptregister (see next lesson), and the R orRefresh register. 1 There are only two instructions involvingthe alternative registers. 1 There are four groups of four types ofinstructions that perform operations onblocks of memory. Since these instructionshave similarities, they are introducedtogether. 1 There is one particular relative jumpinstruction that is particularly usefulnamely Decrement and Jump on Non-Zero, orDJNZ. The B register is decremented and,if the result is not zero, the processorperforms a relative jump to the computednew address. If the result is zero thenthe next instruction in sequence is taken.DJNZ allows us to repeat a series ofinstructions a preset number of times. Thenumber of repeats is equal to the contentsof the B register when the loop isentered, so long as the B register doesnot form part of the series ofinstructions. 1 There is one instruction similar tothis type: EX DE,HL. It EXchanges thecontents of the DE register pair with thecontents of the HL register pair. 1 There are 4 other rotate instructionsthat involve the Accumulator only. Theyare RLCA, RLA, RRCA, and RRA. They areidentical to RLC A, RL A, RRC A, and RR A,but only affect the Carry flag, and aretwice as fast. 1 There are three logical instructionsavailable on the Z80. They are allperformed on a bit by bit basis betweenthe Accumulator and a number, register, orindirectly addressed memory location (HL).The result is left in the Accumulator. 1 Their prime use on some systems isto allow external hardware to forcethe single byte instructions into theprocessor, thus making it think itsnext instruction is an RST n. It thereforeforms a method of interrupting theprocessor. (see the lesson on interrupts). 1 The two registers hold different parts ofa number. Consider the decimal number 27.We can think of this as having two parts;the high part ( or byte) is the 2 since itrepresents 2*10, the low part (or byte) isthe 7, since it only represents 7*1. Thetotal number is 2*10+7*1=27. Each digitcan only be 0 - 9 i.e. 10 differentnumbers. 1 The total list is 1 The step by step instructions making up aprogram are stored in memory, a series ofsimilar registers or memory locations,external to the Z80 chip. 65536 memorylocations can be accessed. They aredesignated by their number between 0 and65535. It takes the Z80 longer to accessmemory than its own internal registers. 1 The stack pointer is outside allocated memory area. Please edit program. 1 The simulator will display the contentsof this memory location, in decimal, inthe second column. 1 The simulator uses the memory area 32000to 32255 for the pupils programs. TheStack Pointer is initially set to 32254,and works its way down towards the programarea. Keep the SP at the top end of thisarea of memory to ensure that thesimulator does not stop. 1 The simplest jump is JP nn, where nn isthe address to which the program is tojump. This is an unconditional jump, theProgram Counter always jumping to theaddress nn. 1 The sign and parity flags can be used inall absolute ( NOT relative) jumps, calls,and returns. 1 The program has been completed. You may EDIT or reRUN. Exit by pressing BREAK. 1 The power of these instructions is wellillustrated by the simple operation. 1 The notation is :- 1 The mnemonic for relative jumps is JR andcan take all the forms discussed so farfor JP, i.e. JR , JR NC, JR C, JR NZ andJR Z. 1 The maximum number that can be held in an8 bit register is 1 The last four pairs of memory locationsin the Stack are displayed at the bottomright hand corner of the screen. As withthe Program Counter, the position to whichthe Stack Pointer points is shown in Cyan. 1 The last arithmetic instructions to bediscussed can be performed on any singleor double register(s). These are INC andDEC. INC increments (or increases) thecontents of the register, or memorylocation indirectly addressed by the HLregister pair, by one. DEC decrements (ordecreases ) the contents of the register,or memory location indirectly addressed bythe HL register pair, by one. 1 The instruction is PUSH dd. Continuing toPUSH data on to the Stack results in thedata being pushed in at the bottom of theStack and the Stack Pointer working itsway down through memory. 1 The instruction INC SP is included at theend of the program to ensure that SP isdisplayed. The actual value in the SPregister is immaterial for most of itsapplications. 1 The important input port on the Spectrumis 254 ( FEH ), it is used for inputtingkeyboard data ( in bits 0-4 , bit 0 beingthe outside key ) and for cassette input. 1 The fact that a single register can onlyhold numbers up to 255 and the totalmemory available is up to 65535, is alimitation. For this reason there are awhole set of instructions on the Z80 thatdeal with registers in pairs. The pairsare BC, DE, and HL register pairs. 1 The examples illustrate the operation ofthe logic instructions. The pupil shouldtest his/her understanding further bymodifying the contents of the 3 stores. 1 The example uses the LDIR instructionto transfer the top third of the screen tothe middle of the screen. 1 The best way to describe these operationsis by example. Both instructions involvethe Accumulator, and the memory location(HL). The examples are in Binary CodedDecimal of course, each digit taking upone nibble or 4 bits of the register ormemory location. 1 The assembler, within this tutor, has oneinstruction not normally found in anassembler, namely BIN. The assemblerallocates one memory location to the line,which would normally be labelled. Itconstantly displays this location inbinary form. The number after BIN is thenumber initially inserted into thelocation. 1 The assembler, that converts instructionsinto machine code, will accept Labels.Instead of putting an address into theprogram, we can give it a name. Theassembler will then allocate a memorylocation to it. The name must be called upin the program with its initial conditionusing the instruction DEFB, DEFine Byte. 1 The Spectrum works on 32 characters perline and not 42 as does the TUTOR 1 The RRD instruction therefore divides thedecimal number by 10. It can also bestrung together to divide any length BCDnumber by 10. The low digit of the twodigit decimal number can be isolated bythis instruction. 1 The F register sometimes forms a registerpair in conjunction with the Accumulator.This pair is called AF. The onlyinstructions previously mentioned thatinvolve this register pair are PUSH andPOP. 1 The BC, DE and HL registers may be PUSHedon to and POPped from the Stack. TheAccumulator may also be PUSHed on to theStack, but this is done with the flagregister F, which will be discussed later. 1 The 3 shift instructions are illustratedusing a fixed initial value in the memorylocation STORE. 1 The zero flag, like the carry flag, isunaffected by any LD or EX instructions. 1 The two types of instructions discussed( LD r,r' and LD r,n ) can involve any ofthe registers considered. Only the Aregister can be loaded with the contentsof a memory location. The instruction ofthe general form LD A,(nn) loads or copiesthe contents of memory location nn( a number between 0 and 65535 ) into theA register. 1 The three logical instructions AND, OR,and XOR affect the Zero, Sign, and Parityflags. The Carry flag is reset to "0" inall cases. Thus the limitation of no ClearCarry instruction can be perfomed simplyby a logical instruction. 1 The state of the individual flags aredisplayed to the left of the registers. 1 The return instruction RET, POPs thereturn address from the Stack, back intothe PC register, to continue where themain program left off. If the number ofPUSHes and CALLs in the subroutine doesnot equal the number of POPs and RETurns,obviously this will not happen. 1 The processor, under the programmer'sdirection, has the capacity to makedecisions. In the following lessons weshall discuss these instructions that makea computer more than just a calculator. 1 The location 23060 holds a number 256less than the start of the Spectrumcharacter set. This example writescharacters along the top line of thescreen. Once you have followed theindividual steps of the program, keepinga key pressed will result in the programbeing stepped through quickly. 1 The largest positive number we can holdin a single register, using this notationis 01111111 or 127 and the largestnegative number 10000000 or -128. 1 The instruction performed determines themeaning of the P/V flag. 1 The hex digit requires adjustment toavoid the digits A-F. Adding 6 to thedigit, if these symbols appear, results incorrect adjustment. 1 The following illustrates the way inwhich SET, RES, and BIT can be used tomanipulate individual bits of a registeror memory location. 1 The examples that follow use the colouras well as labels, so expect some colourchanges. 1 The example uses the IX register as apointer to a table of two byte numbers.Each number is to be divided by 2. 1 The example loads all registers, thenswops them with the alternative set.Having re-loaded the registers a furtherswop returns the original numbers. 1 The example illustrates each type ofinstruction that loads register pairs. Italso demonstrates that a register/memorypair are still two individual registers ormemory locations and can be treated assuch. 1 The colour screen is searched for thefirst blue and white character. In thesecond case the search is too short tofind a match. 1 The carry flag is not affected by eitherof these instructions. 1 The carry flag can be set to a "1" withthe instruction SCF or Set Carry Flag.Although there are no specificinstructions to clear the carry flag to"0" there is an instruction to invert itCCF or Compliment Carry Flag. We shall seelater that all logic instructions do clearthe carry flag. 1 The block instructions stop, not withthe pointer(s) pointing at the addressesjust operated on, but to those about tobe processed. Hence if equality is foundthey point to the next address and notthe memory location in which it was found. 1 The aspect of a computer that makes itmore than a calculator is its ability tochange its sequence of operations as aresult of earlier instructions. Withinthe Z80 there is a counter called theProgram Counter or PC. This counter keepstrack of which instruction the processoris to perform next. By modifying itscontents, the processor can be jumped toany instruction in memory. 1 The arrangement of the screen, and otheruseful memory locations within theSpectrum are given in the TUTOR manual. 1 The address in the first column is thelow byte address. The second columndisplays the contents of the pair ofmemory locations as a single number. 1 The Zero flag indicates B=0 in thesecases 1 The Z80 is the microprocessor at theheart of your Spectrum. This program willteach you the use of all the instructionsavailable on the Z80, in a series ofsimple progressive lessons. 1 The Z80 has a flag that is set if thenumber of "1"s in a number is even. Thisflag is in fact the same flag as theoverflow flag. It is termed the P/V flag. 1 The Z80 allows us to rotate left andright nibbles as well as bits. 1 The U in OUT is dropped to keep themnemonic to a maximum of 4 letters. 1 The Stack is an area of external RandomAccess Memory, that is used as a series ofregister pairs, in conjunction with aStack Pointer. The Stack Pointer (SP) is asingle double length register within theZ80, capable of holding up to 65335. 1 The Stack Pointer can take part in anumber of instructions already discussed. 1 The Simulator can be switched betweendecimal and hexadecimal display bypressing "g", when a program is notrunning. 1 The SRL r, and SRL (HL) instructionsshift the register/memory locationcontents right, shifting bit 0 into theCarry flag and a "0" into bit 7. 1 The SRA r, and SRA (HL) instructionsshift the register/memory location (HL)right, shifting bit 0 into the Carry flagand retaining the state of bit 7. 1 The SLA r, and SLA (HL) instructionsshift the register/memory contents leftshifting a "0" into bit 0 and bit 7 intothe Carry flag. 1 The Refresh register is used by someforms of Random Access Memory whichrequire continuous writing to maintain itsinformation. The R register is incrementedautomatically every time the processorfetches each part of an instructionfrom memory. This provides the programmerwith a register whose contents may beconsidered random for some applications. 1 The R and I registers can be loaded fromthe Accumulator. The instructions involvedare simply LD A,R : LD R,A : LDA,I andLD I,A. 1 The OUT group is identical to the INgroup, but data from memory is output toport (C) in sequence from memorybeginning at location (HL) 1 The IN group of block instructionsinput data from the input port specifiedby the contents of the C register intoa block of memory starting at the addressheld in the HL register, the length ofwhich is in the B register. All forms ofIN apply:- 1 The B register is used as a counter asthe IN group. 1 The summary lists all instructionsavailable using the IX register. This listcan be repeated for the IY register. 1 The operation luckily also makes anegative number positive. A veryimportant point. 1 The only instruction for which (HL)cannot be substituted by (IX+d) or (IY+d)is JP (HL). JP (IX) and JP (IY) areavailable however. 1 The great advantage of the indexregisters however is that indirectaddressing is not simply (HL) but (IX+d). The indirect address is calculated as thethe sum of the contents of the IX/IYregister and the offset d specifiedin the instruction. This offset can beany number between 0 and 255. 1 The first example shows nesting ofsubroutines : a subroutine being calledfrom within another subroutine. 1 The example adds together the twonumbers 8740 and 1260 using singleregister addition only. The double lengthnumbers are held in BC and DE so that theresults can be displayed easily. Thismethod of addition can be performed usingregister pair addition, as well, to addtogether numbers of any length. 1 The conditional jumps involving thecarry and zero flags are:- 1 The Z80 allows this feature by theinstruction CALL. The CALL instruction issimilar to the JP instruction except thatthe address of the next sequentialinstruction, held in the PC register, isPUSHed onto the Stack, prior to the jump. 1 The Z80 has within the chip analternative set of the primary registersAF, BC, DE and HL. These are normallydesignated as AF', BC', DE' and HL'.Although no operations can be performed onthese registers, they can be used as afast method of storage. 1 The Z80 accommodates the aboveadjustment, with the instruction DAA,Decimal Adjust Accumulator. Thisinstruction is used after an 8 bit ADD,ADC, SUB, or SBC to adjust the Accumulatorcontents by adding 6 to the nibble, ifeither nibble in the answer is above 9. 1 The SRL or Shift Right Logicallyinstruction therefore divides a positivenumber by 2. As with SRA the Carry flagindicates the half. 1 The more powerful jump is theconditional jump. The processor tests thestate of a flag, before either jumping orcontinuing in sequence. 1 The load instruction is normallyabbreviated to LD. The simplest form ofload copies data from one register toanother, i.e. LD A,B . 1 Taking the initial conditions :- 1 Taking our number 10111000 for exampleand noting that bits that are "0"contribute nothing to the number, thedecimal equivalent of 10111000 is given by 1 Take the hex number C (= 12 dec.). Adding6 gives 18 decimal or 12 hex. Hence thehex number looks identical to the decimalanswer required. 1 Take the example of an LDIR instructionwith the registers initially set to:- 1 Summary - zero and carry flags 1 Summary - the Stack and SP register 1 Summary - simple input/output 1 Summary - shift instructions 1 Summary - rotate instructions 1 Summary - relative jumps 1 Summary - processor control instructions 1 Summary - logical instructions 1 Summary - jumps 1 Summary - index registers 1 Summary - increment and decrement 1 Summary - decimal shifts 1 Summary - comparisons 1 Summary - calls and returns 1 Summary - block transfer 1 Summary - block search 1 Summary - bit manipulation 1 So far we have only dealt with positivenumbers. If we had taken 6 from 5 we wouldend up with the answer 255 with the carryset. There is an interpretation of binarynumbers that allows us to consider thisanswer as the negative number -1. 1 So far we have manipulated data withinthe processor and its associated memory. Our Simulator examples have shownhow to write to the TV screen, (usingmemory locations 4000H to 5AFFH). Thistype of output is termed memory addressmapped since it looks like memory. The Z8Oalso supports 256 output and 256 inputports, or 8 bit information sources,external to memory. 1 So far all instructions we have discussedthat affect the Carry or Zero flags alsoaffect the register concerned. There are anumber of useful instructions that onlyaffect flags. The compare or CPinstruction is one of these. 1 Single and double register additions willobviously only give the correct result ifthe answer is less than the maximum numberthe register(s) can hold. If it is greaterthan this a carry is generated. Theprocessor holds this single bit ofinformation or flag, so that action can betaken over the occurrence of the carry. Ifthere has been a carry on the lastarithmetic operation the carry is said tobe set to a "1". If not set it is said tobe a "0". 1 Single register subtraction takes placewith the Accumulator. All the forms of ADDcan be used in subtract. The abbreviationor mnemonic SUB is always written withoutthe A, which is implied. Hence theinstructions are SUB n, SUB r, andSUB (HL). Again the result is held in theAccumulator. The carry flag is set to a"1" if the result is outside the range 0-255. 1 Since all RST calls are to the beginningof memory (page 0) and this area on theSpectrum is ROM, all the calls have beendefined i.e. RST 00H is equivalent toNEW, that clears out all the memory andre-establishes the system. Needless tosay the simulator does not perform RSTinstructions. 1 Since double register subtraction canonly be performed with carry, the state ofthe carry flag prior to SBC HL,BC, andSBC HL,DE is important, and should be "0". 1 Similarly, memory locations can be loadedindirectly from any single register usingthe contents of the HL register pair asaddress i.e. LD (HL),C. 1 Similarly, we can load the contents of aregister pair into a pair of memorylocations, i.e. LD (nn),BC which isequivalent to the two non-validinstructions LD (nn),C and LD (nn+1),B. There are no instructions to loadregister pairs with the contents ofanother register pair. Two instructions inthe form LD r,r' are usually used toperform such an operation. 1 Similar we can perform subtraction. 1 SUMMARY - subtract with carry 1 STORE DEFW 6000 1 STORE DEFW 32000 1 STORE DEFW 254H 1 STORE DEFW 0 1 STORE DEFB 7 1 STORE DEFB 64 1 STORE DEFB 25 1 STORE DEFB 124 1 STORE BIN 16 1 STORE BIN 15 1 ST3 BIN 0H 1 ST2 BIN FH 1 ST1 BIN 65H 1 SRL r divides +ve numbers 0 - 255 by 2 1 SRA r divides +ve and -ve numbers by 2 1 SR2 LD A,(HL) 1 SR1 CALL SR2 1 SLA r multiplies +ve and -ve numbers 1 SBC HL,SP 1 Remember, it is impossible for a programto destroy your computer. You'll need aa hammer to do that! 1 Registers are like pigeon holes in whichnumbers can be stored. A single registercan store any number between 0 and 255.The Z80 has many such registers. Initiallywe shall consider only the more generalones: designated A,B,C,D,E,H and L. The A( commonly called the Accumulator ) is themost important, since more instructionsinvolve this register than any other. 1 Register pair addition is performed inconjunction with the HL register pair, andcan only involve BC or DE ( i.e. ADD HL,BCor ADD HL,DE ). Again the result is heldin the HL register pair, and the otherregister pair is unaffected. 1 RRD Rotates the Decimal number Right 1 RRCA rotate A right, carry duplicates 1 RRC r, RRC (HL) instructions (RotateRight Carry being duplicated ) is similarto the RLC instruction but is a rightshift. Bit 0 is shifted into bit 7 and theCarry duplicates the old bit 0. 1 RRC r rotate r right, carry duplicates RRC (HL) 1 RRA rotate A and Carry right 1 RR r rotate r and Carry right 1 RR instructions can be strung together todivide any length number by 2. 1 RLD Rotates the Decimal number Left 1 RLCA rotate A left, carry duplicates 1 RLC r, and RLC (HL) ( namely Rotate LeftCarry duplicating ), shifts the contentsleft, bit 7 rotating into bit 0, and theCarry duplicating the transferred bit. 1 RLC r rotate r left, carry duplicates RLC (HL) 1 RLC and RRC instructions are useful insequentially interrogating the wholecontents of a register without corruptingits contents. 1 RLA rotate A and carry left 1 RL r, and RL (HL) Rotate Left, rotatesthe register/memory location with theCarry as a 9th bit, left. 1 RL r rotate r and carry left 1 RL instructions can be strung together tomultiply any length number by 2, since theCarry is transferred between repeated RLinstructions. 1 Program stopped. You may re-RUN, EDIT or press BREAK to return to menu. 1 Program has successfully assembled. Press RUN, EDIT, or exit by pressing BREAK. 1 Program counter has jumped to non-valid address. EDIT or reRUN program. 1 Proceed through the menu by pressingENTER to begin the highlighted lesson orexample, and SPACE to jump to the next. Atanytime BREAK will return you to themenu. 1 Press SPACE to select and ENTER to start 1 Press RUN to begin example, EDIT to edit, and BREAK to return to menu. 1 Please confirm tape loading required Y/N 1 Perhaps a better description of load thanthe conventional one is copy, since a loadinstruction copies the number held in aregister or memory location into anotherregister or memory location. As with allcopying the original remains unchanged. 1 PUSH DD where DD is AF, BC, DE, or HL. From now on dd can be considered as BC, DE, HL,or SP. 1 POP dd retrieves data from the Stack intothe defined register pair. The registerpair is loaded with the contents of thememory location pointed to by SP. Then theSP register is incremented twice. 1 Output port 254 is used to set the bordercolour ( bit 0-2 ), and output to cassette( bit 6 ). 1 Output OUT/OT..OUTI,OTDR,OUTD,OTDR 1 Of all the instructions described to dateonly DAA treats it as a parity flag. Allothers either have no effect on it or useit as an overflow flag. All subsequentinstructions either have no effect on itor use it as parity. 1 OUTI incrementing 1 OUTD decrementing 1 OUT (C), r is a similar instruction toIN r,(C), but the contents of the registerr is loaded into port (C). 1 OTIR incrementing and repeating 1 OTDR decrementing and repeating 1 Now that hex notation has been introducedwe can discuss how the computer storesprograms in more detail. As alreadymentioned, the instructions are stored inmemory as numbers. Some instructions onlyrequire a single number, others requiremore. Column 2 on the Simulator displayshows the memory contents for theinstructions in hex form. 1 No flags are affected by any jumpinstructions including DJNZ. 1 NUM2 DEFW 8740 1 NUM2 DEFB 203 1 NUM2 BIN 95 1 NUM1 DEFW 1260 1 NUM1 DEFB 212 1 NUM1 BIN 81 1 NOP or No OPeration causes the processorto do nothing for one step. Since its codeis 0, a cleared memory area will besequenced through until a non-zeroinstruction is found. 1 Most of the instruction in this and thelast lesson involve steps that change theenvironment in which the processoroperates. It is therefore difficult tosimulate these instructions. Little can belearnt from single stepping through anexample. However changing interrupt modesetc. ( see next lesson ) on a PersonalComputer is advanced programming. Trygaining experience on machine codeprogramming before venturing into thisfield. 1 Luckily assemblers takes account of allthese complexities, and you will not berequired to learn the tables inAppendix A of your Spectrum Manual. 1 Like ADC instructions SBC instructionscan be strung together to subtract anylength number. 1 LREG BIN 0 1 LOW DEFB 20 1 LOW DEFB 0 1 LOOP4 RR (HL) 1 LOOP3 SRL (HL) 1 LOOP3 RRC (HL) 1 LOOP2 SLA (HL) 1 LOOP2 RL (HL) 1 LOOP2 LD A,(DE) 1 LOOP2 DEC (HL) 1 LOOP2 ADC HL,BC 1 LOOP1 SRA (HL) 1 LOOP1 SBC HL,DE 1 LOOP1 RLC (HL) 1 LOOP1 LD (STORE),HL 1 LOOP1 LD (HL),A 1 LOOP SRL (IX+1) 1 LOOP RR A 1 LOOP LD HL,5800H 1 LOOP LD C,FEH 1 LOOP LD B,32 1 LOOP LD A,(HL) 1 LOOP INC (HL) 1 LOOP EXX 1 LOOP DEC (HL) 1 LOOP ADD HL,DE 1 LDIR is similar to LDI, transferring datafrom (HL) to (DE) and incrementing thepointers, but this instructionautomatically repeats the operation untilBC=0 and the whole block is transferred. 1 LDI transfers (HL) to (DE), incrementsboth pointers, and decrements BC. If BC=0the P/V flag is 0 (i.e. equivalent toparity being odd ). If BC does not = 0the P/V flag is 1 ( parity even ). LDItherefore performs only one step of thetransfer of the block, allowingintermediate operations to be performedbefore the instruction is repeated. 1 LDDR Repeats LDD until BC=0 as in theLDIR instruction. 1 LDD is similar to LDI except the pointersare Decremented. Thus HL and DE start atthe top of the respective blocks ofmemory. 1 LD SP,(nn) 1 LD HL,ST2 1 LD HL,NUM1 1 LD HL,LOW 1 LD HL,56789 1 LD HL,4000H 1 LD HL,257 1 LD HL,23040 1 LD HL,(STORE) 1 LD DE,8740 1 LD DE,256 1 LD DE,(23606) 1 LD BC,100H 1 LD A,(STORE) 1 LD (nn),SP 1 Just as we can combine two registers tohold numbers up to 65535, we can combineadjacent memory locations. Conventionallythe Low byte is held in the location withthe Lower address. 1 Just as we add two decimal numberstogether, carrying one forward if the sumof two digits is greater than 9, we canadd two binary numbers. If the sum isabove one, a one is carried forward. 1 JP1 RET Z 1 JP PO,nn CALL PO,nn RET PO Parity odd =0 1 JP PE,nn CALL PE,nn RET PE Parity even =1 1 JP P,nn CALL P,nn RET P Sign +ve 1 JP M,nn CALL M,nn RET M Sign -ve 1 It must be remembered that a subroutinemay require the use of a register whosecontents are still required in the mainprogram. Its contents must therefore bePUSHed onto the stack or otherwise storedelsewhere, and retrieved at the end of thesubroutine. 1 It is easier to use the index registersto interrogate tables than using HL. Theoffset can define the column in the tableand IX/IY register point to the beginningof the line. A subroutine could manipulatethe data within the line, using a constantIX/IY pointer. Subsequent lines can thenbe manipulated simply by using the samesubroutine and changing the IX/IY registerto point to a different line. 1 It is only affected by double registerarithmetic operations involving the carryflag, i.e. only affected by ADC HL,dd orSBC HL,dd. 1 Input IN .....INI,INIR,IND,INDR 1 Indirect jumps are also available on theZ80 using the HL register pair. Theinstruction JP (HL) loads the programcounter with the contents of the HLregister. Thus the address of the nextinstruction to be performed is equal to the contents of the HL register. 1 In this interpretation -1 must equal 255or 11111111, or the processor would notbe able to take 6 from 5 and get theright answer. Further 5 - 7 = -2 or 254or 11111110. Bit 7, the most significantbit, represents the sign ( + or - ) ofthe number. When bit 7 is "1" the numberis negative, and when "0" the number ispositive. 1 In general, if the two blocks overlap usethe instruction that ensures the initialfigure in the HL register lies within theblock to which data is to be transferred. 1 In a register each digit or bit has onlytwo states. Therefore we can interpret thedigits as having weightings of 1 In these abbreviationed instructions( mnemonics ), it is conventional to putthe register affected first, followed bythe register from which the information iscopied. Hence LD A,B copies the contentsof B into A or Accumulator. 1 In the XOR ( eXclusive OR ) instruction,if the bit in the Accumulator is the sameas that in the number , then thecorresponding bit in the result will be"0". If they are different it will be "1".Another way of looking at the XORinstruction is if one OR the other is "1"but NOT both, the answer will be "1". 1 In the OR instruction, if a bit in theAccumulator OR in the other number is a"1", the corresponding bit in the resultwill be "1". If not it will be "0" 1 In the AND instruction, if a bit in theAccumulator AND other number are "1",then the corresponding bit in the resultwill be "1". If not it will be "0" 1 If we were to take the top off a Z80 chipand, using a powerful microscope, look ata register, we would see that it consistsof 8 cells. These cells are capable ofbeing switched between two differentstates. Conventionally we designate onestate as "1" and the other as "0". Thepattern of 1's and 0's could be 10111000say. 1 If the condition is not met, the programwill not CALL the subroutine or RETurnfrom it. 1 If the condition is not met the programwill not jump, call a subroutine orreturn. 1 If n is the number with which A iscompared, then the following results :- 1 If a series of registers is PUSHed on tothe Stack, and subsequently POPped off theStack, they reappear in the reverse order. 1 ITEM1 DEFW 560 1 INC and DEC really only become useful inconjunction with instructions to beintroduced shortly. 1 IN r, (C) affect the Zero, Sign, andParity flags. The instruction IN F, (C) isthe only instruction that deals with theFlag register separately. Only the flagsare affected by this instruction and nodata is transferred into the processor. 1 How do we interpret this pattern? Theamswer is, anyway we like. In this lessonwe show that this pattern could be184, -72, B8H, and even CP B. The only onethe processor has built into it is thelatter. 1 Hence the result of the instruction SLAor Shift Left Arithmetically is tomultiply the positive number by 2. TheCarry indicates a result greater than 255. 1 Hence the SRA or Shift RightArithmetically instruction divides bothpositive and negative numbers by 2. 1 HREG BIN 0 1 HIGH DEFB 125 1 HIGH DEFB 0 1 HALT stops the sequencing of theprocessor until an interrupt is received( see next lesson ). After the interrupthas been dealt with, the instruction afterthe HALT is performed. Thus the programcan be synchronised with operationsoutside the processor. 1 Each time the program loops round press adifferent key between "H" and "ENTER" toinput a different number. Setting C to BFHinterrogates keys in this range. SeeManual. 1 Each digit in a number can be consideredto have a weighting. For decimal numbersthese weightings are 1 Each digit is held in 4 bits of theregister. These 4 bits are called anibble, the whole 8 bit word is termed abyte. Who said programmers have no senseof humour? 1 EXX exchanges BC,DE and HL, with BC', DE' and HL' respectively. 1 EX AF,AF' exchanges the contents of AF and AF' 1 EX (SP),HL 1 DEFM " LD DE,22528 1 DEFB is an assembler instruction not aZ80 instruction. The allocated memoryaddress is given in the first column. 1 Conversion of a hex number to its decimalequivalent follows the standardcalculation. 1 Continuing to POP data from the Stackresults in information being POPped fromthe bottom of the Stack and the StackPointer working its way back up throughthe memory. 1 Compare CP .....CPI,CPIR,CPD,CPDR 1 Colour is used to illustrate registerpair subtraction. Although ADC and SBC mayrequire the Carry flag to be cleared firstif the previous calculation NEVER resultsin a carry being generated, this step maybe omitted. However it is often better tobe safe and include it, than look for therandomly occurring fault that it cangenerate. 1 CP compares the contents of the Aregister with a number (CP n), anotherregister (CP r), or any memory locationindirectly addressed through the HLregister pair ( CP (HL) ). The compareinstruction is effectively SUB but theresult does not affect the contents of theA register. 1 But first we shall look further at theprocessors flags. 1 Both conditional and unconditional CALLsand RETurns are available on the Z80. Allfour types of conditions alreadyconsidered ( NC, C, NZ and Z ) can beused with CALLs and RETurns. 1 Both single register and register pairaddition are possible on the Z80. 1 Both pairs of instructions ( LDIR andLDDR) are required. 1 Block transfer instructions transfer thecontents of an area of memory to anotherarea. Two pointers are used. The HLregister holds the source address and theDE register the destination address. Thesize of the block to be transferred isheld in the BC register. 1 Binary numbers are too cumbersome anddecimal too inconvenient to displaymultiple register numbers. A method ofpresenting binary numbers has beendeveloped to get round these problems.Instead of basing the number on 10 as indecimal or 2 as in binary, we base it on16. This numbering system is calledHexadecimal. 1 Before each instruction is executed theinstruction is described in ENGLISH. Tryto work out what should happen beforepressing any key to perform theinstruction. 1 Before loading the Stack from anyinternal register pair, the Stack Pointeris decremented twice, ( thus pointing tothe next pair of memory locations ). Thecontents of the register is then loadedinto the Stack indirectly using the SPregister as the address. 1 Because a repeated block input is sofast the whole block of memory is likelyto be filled with the single key press.It does however illustrate the operation. Try different keys as before. 1 BELOW INC D 1 At present the programs that can bewritten are somewhat limited. 1 As well as the standard CALL instructionsthat incorporate the address to which theprocessor is to jump, the Z80 hasinstructions in which the address of theCALL is implied. The instructions RST n(where n=00H, 08H, 10H, 18H, 20H, 28H, 30Hor 38H ) calls the routine at 00n hexdirectly. i.e. RST 28H is equivalent toCALL 0028H. 1 As well as performing OR operations onour own flags, this instruction is usefulin SETting a group of bits in theAccumulator. 1 As can be seen the effect of stringingtogether RLD instructions is to multiply adecimal number by 10. It is also useful inisolating the high digit from the twodigit number. 1 As you may now be able to infer, the CPgroup Compares the content of memorylocations in a block of memory with apredetermined number. HL holds thepointer and the BC register the lengthof the block to be searched. TheAccumulator holds the number for whichthe instruction will search. If thenumber is found then the Zero flag isset. As before the P/V flag indicateswhether BC=0. 1 As well as performing ANDs on our ownflags, this instruction is useful inmasking off areas of words, or resettinggroups of bits in the Accumulator. 1 Apart from performing the logical XORfunction on our own flags the XORinstruction is useful in invertingindividual or groups of bits. 1 Any bit in a register, or memorylocation using (HL), can be SET to a "1".We can also RESet any bit to a "0". Totest the state of a bit in a register, ormemory location, we can use theinstruction BIT. In this instruction theZero flag is set if the appropriate bitis "0" and reset to a "0" if theappropriate bit is "1". Hence we canproduce our own flags to indicate eventsand then act upon them later in ourprograms. 1 Another very useful flag included in allprocessors is the Zero flag. This flag isset to "1" if the result of any singleregister arithmetic operation is zero.Otherwise it is cleared to"0". 1 Another assembler instruction isintroduced, the DEFW instruction. Theassembler allocates 2 memory locations tothe associated label. The number after theDEFW sets the initial conditions. 1 An area of memory that illustrates wellthe use of instructions is the screen.This area has the following addresses:- 1 Always remember that a hex number has abase of 16 decimal, a decimal number has abase of 10 and a binary number a base of2. 1 Although you can enter the address withinthe jump in number form, if it does notequal the address of the start of aninstruction, the simulator will stop atthe JUMP. This is because the processorwould perform the instruction it findsat that address and anything could happen,and usually does. 1 All the above rotate instructions RLC,RL, RRC, and RR not only affect the Carryflag but also the Zero, Sign and Parityflags, as have all shift instructionsdiscussed. 1 All single registers can be loaded usingthe HL register pair as a pointer. 1 All examples are run using the Simulator.At this stage the only areas of thesimulator screen to consider are theSource Code ( the third column that holdsthe instructions ) and the area at thebottom of the screen, which displays thecontents of the registers. Other areaswill be described as they are required. 1 All assemblers calculate the displacementfor relative jumps. The assembler withinthis TUTOR is no exception. Relative jumpsshould be entered with labels. 1 All the numbers used to describe aninstruction are given in sequence alongthe line. Notice that numbers called up inan instruction appear towards the end ofthe string of numbers. The earlier numbersdetermine the type of instruction. Sincethe total number of instructions exceed256, a prefix number is used to produceother sets of instructions. The prefixesyou will find are EDH, CBH, DDH and FDH. 1 All other single registers cannot beloaded directly from a memory location.Such operations require two instructionsvia the A register. 1 All block instructions use register(s)as a pointer(s) to scan though a blockof memory and another as a counter. 1 All block instructions have similarmnemonics. I indicates that thepointer(s) are Incremented, D thatthe pointer(s) are Decremented, and Rthat the instruction is to be repeateduntil the counter is zero. 1 All 16 states of the 4 binary bits arecovered by 0-F. Hence only 2 hexadecimaldigits are required to display thecontents of an 8 bit register. Our example10111000 divides up into 1011 1000 orB8 Hex. A double register holding say11001001 10111000 will be represented byC9B8 hex. 1 All single register additions areperformed with the Accumulator. A number(i.e. ADD A,6), the contents of a register(i.e. ADD A,B), or the contents of anindirectly addressed memory location usingthe HL register pair (i.e. ADD A,(HL) )can be added to the Accumulator. Theresult is held in the Accumulator. Thesource of the addition is unaffected. 1 ANS DEFW 0 1 ANS BIN 0 1 AND A or OR A will clear the carry flagand not affect any registers. XOR A willclear Carry and the Accumulator. 1 ADD HL,SP 1 ADC HL,SP 1 ADC instructions can be strung togetherto perform the addition of two numbers ofany length, as the examples will show. 1 ABOVE INC E 1 A subroutine is a part of a program thatis called from the main program and oncecompleted returns back to the mainprogram. The subroutine is usually calledfrom a number of places in the program. 1 A second form of addition is available onthe Z80, for both single and multipleregisters, known as add with carry;abbreviated to ADC. They are similar toADD except that if the Carry flag is setbefore the addition the result isincremented by one. All previouslymentioned ADD instructions can beperformed as ADC. 1 A useful operation would be to make apositive number negative. Changing bit 7does not do this. Take the positivenumber 2 or 00000010 and its negativeequivalent -2 or 11111110 for an example.Inverting all bits of the binary number of+2 gives 11111101, which is 1 less thanthat for -2. 1 A single register can hold 0-255, 256different numbers. If we put two registersside by side, such as HL, the H registerholding the High byte and the L holdingthe Low byte, then we can hold in theregister pair the number H*256+L*1 in thesame way as 27=2*10+7*1. The maximum thatcan be held in a register pair istherefore 255 * 256 + 255 = 65535. Byconvention the high byte is stored inthe first register in the register pairname. 1 A shift instruction is one in which thebits of a register or memory location aremoved sideways, left or right to theadjacent bit. As we shall see, this givesus a means of division as well asmultiplication. 1 9. Compare 1 8. Zero Flag 1 7. Increment and Decrement 1 6. Subtraction and the Carry Flag 1 5. Addition and the Carry Flag 1 4. Indirect Addressing 1 3. Register Pairs 1 25. Decimal rotating 1 24. Rotate instructions 1 23. Shift instructions 1 22. Logical instructions 1 21. Bit manipulation 1 20. S and P/V flags in instructions 1 2. Simple Load Instructions 1 19. The flag register and AF 1 18. Parity 1 17. Positive and negative notation 1 16. Binary Coded Decimal notation 1 15. Hexadecimal notation 1 14. Binary notation 1 13. Calls to subroutines 1 12. The Stack 1 11. Relative jumps 1 10. Conditional and unconditional jumps 1 1. Registers and Memory 1 0 1 0 0 0 1 1 1 parity flag is set since number of "1"s is 4 1 0 0 1 1 0 1 0 0 parity flag is not set since number of "1"s is 3 i.e. odd. 1 & clears all ENTER tabs to next line STOP assembles SPACE tabs in label are 1 or 1 1 1 0 0 0 1 0 x (-30 dec.) 1 gives 1 0 0 1 0 0 1 1 1 gives 0 0 1 1 1 0 0 1 1 add 1 1 1 1 1 1 0 1 1 -5 1 add 1 0 0 0 0 0 1 0 1 +5 1 XOR (HL) 1 THE FLAG REGISTER AND AF REGISTER PAIR 1 SUB (HL) 1 SUB * n/v * n/v 1 SET 6,(HL) 1 SBC A,(HL) 1 SBC * * * * 1 RR (IX+0) 1 RES 3,(HL) 1 OUT (C),D 1 OUT (254),A 1 Loading error 1 LD IX,ITEM1 1 LD HL,NUM2 1 LD HL,HIGH 1 LD HL,64000 1 LD HL,581FH 1 LD HL,5800H 1 LD HL,4589H 1 LD HL,32100 1 LD HL,22550 1 LD HL,22528 1 LD HL,16384 1 LD HL,1000 1 LD HL,(STORE) 1 LD HL,(LOW) 1 LD E,(HL) 1 LD DE,NUM2 1 LD DE,8000 1 LD DE,4800H 1 LD DE,3812H 1 LD DE,34567 1 LD DE,33 1 LD DE,256 1 LD DE,2468H 1 LD DE,22528 1 LD DE,200 1 LD DE,(STORE) 1 LD DE,(NUM2) 1 LD C,FEH 1 LD C,254 1 LD C,(HL) 1 LD BC,800H 1 LD BC,32021 1 LD BC,32 1 LD BC,1280 1 LD BC,1260 1 LD BC,12345 1 LD BC,10H 1 LD BC,1024 1 LD B,20H 1 LD A,255 1 LD A,(BC) 1 LD A,(22530) 1 LD (STORE),HL 1 LD (STORE),DE 1 LD (STORE),A 1 LD (LOW),DE 1 LD (HL),A5H 1 LD (HIGH),A 1 LD (BC),A 1 LD (ANS),HL 1 LD (ANS),A 1 LD . . . . 1 JR Z,LOOP 1 JR NC,JP1 1 JP P,LOOP1 1 JP NZ,LOOP2 1 JP NZ,LOOP1 1 JP M,LOOP2 1 INC (HL) 1 INC . . * . 1 IN A,(C) 1 Error found during assembly. Please correct before running program. 1 EXAMPLE USING REGISTER PAIR SUBTRACTION 1 EX DE,HL 1 EX (SP),HL 1 EX n/v . n/v . 1 Digit 3 2 1 0 1 DJNZ SR1 1 DJNZ LOOP4 1 DEFW 9634 1 DEFW 884 1 DEFW 5937 1 DEFW 187 1 DEC (HL) 1 DEC . . * . 1 CALL SR1 1 CALL NC,ABOVE 1 CALL C,BELOW 1 BIT 2,(HL) 1 After each lesson, step by step examplesare given. To further improve yourunderstanding of the topic, you may thenmodify or rewrite the examples, and runthem without fear of crashing the system. 1 AND (HL) 1 ADD A,230 1 ADD A,128 1 ADD * * * . 1 ADC HL,HL 1 ADC * * * * 1 A > n 0 0 1 A = n 0 1 1 A < n 1 0 1 bit 7 S Sign 1 bit 6 Z Zero 1 bit 5 Not used 1 bit 4 H Half carry 1 bit 3 Not used 1 bit 2 P/V Parity and overflow 1 bit 1 N Subtract last 1 bit 0 C Carry 1 Summary - loading register pairs 1 INCREMENT AND DECREMENT INSTRUCTIONS 1 EXAMPLES OF INPUT/OUTPUT INSTRUCTIONS 1 EXAMPLE OF SINGLE REGISTER SUBTRACTION 1 Do you wish to enter lessons? Y/N 1 Detail area 16384 to 22527 1 Colour area 22528 to 23295 1 CALL Z,nn RET Z Zero set 1 CALL NZ,nn RET NZ Not Zero 1 CALL NC,nn RET NC No Carry 1 CALL C,nn RET C Carry set 1 ASSEMBLED CODE LABELS INSTRUCTIONS 1 invert 1 1 1 1 1 0 1 0 1 invert 0 0 0 0 0 1 0 0 1 Summary - Loading single registers 1 Summary - indirect addressing 1 Summary - addition 1 POSITIVE AND NEGATIVE NUMBER NOTATION 1 EXAMPLES OF SINGLE REGISTER ADDITION 1 EXAMPLE OF USE OF REFRESH REGISTER 1 Decimal Binary Hexadecimal 1 THE ALTERNATIVE SET OF REGISTERS 1 SUBTRACTION AND THE CARRY FLAG 1 INTRODUCTION TO RUNNING SIMULATOR 1 EXAMPLES OF SHIFT INSTRUCTIONS 1 EXAMPLES OF ROTATE INSTRUCTIONS 1 EXAMPLES OF LOGICAL INSTRUCTIONS 1 EXAMPLES OF HEXADECIMAL NOTATION 1 EXAMPLE USING THE ALTERNATIVE SET 1 EXAMPLE OF USE OF INDEX REGISTER 1 EXAMPLE OF REGISTER PAIR ADDITION 1 EXAMPLE OF INCREMENT AND DECREMENT 1 S and P/V FLAGS IN INSTRUCTIONS 1 EXAMPLES OF INDIRECT ADDRESSING 1 EXAMPLE USING ROTATE AND SHIFT 1 EXAMPLE OF CALLS TO SUBROUTINE 1 BLOCK INPUT/OUTPUT INSTRUCTIONS 1 PROCESSOR CONTROL INSTRUCTIONS 1 INIR incrementing and repeating 1 INDR decrementing and repeating 1 IND decrementing 1 EXAMPLES OF DECIMAL ROTATION 1 EXAMPLES OF BIT MANIPULATION 1 EXAMPLES OF BINARY NOTATION 1 EXAMPLE OF CONDITIONAL CALLS 1 BINARY CODED DECIMAL NOTATION 1 ADDITIONS AND THE CARRY FLAG 1 9 1001 9 1 8 1000 8 1 7 0111 7 1 6 0110 6 1 5 0101 5 1 4 0100 4 1 3 0011 3 1 2 0010 2 1 15 1111 F 1 14 1110 E 1 13 1101 D 1 128 64 32 16 8 4 2 1 1 12 1100 C 1 11 1011 B 1 10 1010 A 1 1 0001 1 1 0 0000 0 1 SIMPLE LOAD INSTRUCTIONS 1 Please stop tape recorder 1 Please start tape recorder 1 Loading has been stopped 1 INPUT AND OUTPUT INSTRUCTIONS 1 EXAMPLE OF BLOCK TRANSFER 1 EXAMPLE OF BLOCK SEARCH 1 BLOCK TRANSFER INSTRUCTIONS 1 x 1 0 1 1 0 0 0 1 1 x 0 1 1 0 0 0 1 0 (98 dec.) 1 c 1 0 1 1 0 0 0 1 1 EXAMPLES USING THE STACK 1 EXAMPLE OF JUMP ON SIGN 1 EXAMPLE OF BLOCK INPUT 1 1 0 1 1 0 1 1 1 x (183 dec.) 1 1 0 1 1 0 0 0 1 x 1 1 0 1 1 0 0 0 1 c 1 0 1 1 0 0 0 1 0 x (98 dec.) 1 REGISTERS and MEMORY 1 REGISTER PAIR EXAMPLES 1 Loading lessons 26-35 1 Loading lessons 18-25 1 Loading lessons 10-17 1 EXAMPLES OF ZERO FLAG 1 EXAMPLES OF JUMPS 1 128+64+32+16+8+4+2+1=255 1 - 0 0 1 0 1 1 0 1 1 + 0 0 1 0 0 1 0 1 1 register 1 Loading lessons 1-9 1 LOGICAL INSTRUCTIONS 1 INDIRECT ADDRESSING 1 HEXADECIMAL NOTATION 1 Ex - zero flag 1 Ex - unconditional calls & rets Ex - conditional calls 1 Ex - single register addition 1 Ex - simple load instructions 1 Ex - shift instructions 1 Ex - rotate instructions 2 1 Ex - rotate instructions 1 1 Ex - relative jumps 2 1 Ex - relative jumps 1 1 Ex - register subtraction 1 Ex - register pair subtraction 1 Ex - register pair loading 1 Ex - register pair addition 1 Ex - pushes and pops 1 Ex - logical instructions 1 Ex - jumps 1 Ex - indirect addressing 1 Ex - inc and dec instructions 1 Ex - hex notation 1 Ex - decimal rotation 1 Ex - comparison instructions 1 Ex - bit manipulation 1 Ex - binary notation 1 Ex - BCD notation 1 Ex - +ve and -ve numbers 1 EXAMPLES OF COMPARE 1 1000 100 10 1 1 01010110 ORed together 1 01010110 ANDed together 1 01010110 XORed together 1 nn is a number 0 - 65535 1 THE ZERO FLAG 1 SHIFT INSTRUCTIONS 1 Lessons 1 - 9 1 CALLS TO SUBROUTINES 1 BC, DE, and HL. 1 128+32+16+8=184. 1 ROTATE INSTRUCTIONS 1 RELATIVE JUMPS 1 REGISTER PAIRS 1 Loading error 1 INTRODUCTION 1 Ex - sign and parity flags 1 BLOCK INSTRUCTIONS 1 BIT MANIPULATION 1 BINARY NOTATION 1 = 11*16+8=184 1 0 1 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 1 LESSONS 18 - 25 1 INDEX REGISTERS 1 Lessons 10 - 17 1 DECIMAL ROTATE 1 x 5 4 3 1 r dd r dd 1 COMPARE 1 BLOCK SEARCH 1 THE STACK 1 i.e. even. 1 PARITY 1 JUMPS 1 Carry Zero 1 5 4 x 3 1 and Carry 1 by 2 1 (HL)